package com.doyoulike.controller;

import com.doyoulike.common.CommonResult;
import com.doyoulike.service.table.GenDataBaseService;
import com.doyoulike.vo.in.GetTableListVO;
import com.doyoulike.vo.out.DataBaseColumnVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 这里负责两件事情：
 *  1. 获取当前数据库所有的表
 *  2. 根据表名称查询列的信息
 * @author duzhou
 */
@Api(value = "数据库表数据", tags = "数据库表数据")
@RestController
@RequestMapping("/base")
public class GenDataBaseController {

    @Autowired
    GenDataBaseService genDataBaseService;

    @ApiOperation(value = "获取当前数据库所有的表")
    @PostMapping("/getTableList")
    public CommonResult<PageInfo> getTableList(@RequestBody GetTableListVO getTableList) {
        return CommonResult.success(genDataBaseService.getTableList(getTableList));
    }

    @ApiOperation(value = "根据表名称查询列")
    @RequestMapping(value = "/getTableColumnList", method = RequestMethod.GET)
    public CommonResult<List<DataBaseColumnVO>> getTableColumnList(String tableName) {
        return CommonResult.success(genDataBaseService.getTableColumnList(tableName));
    }
}
